/*
 * TowerFactory.cs
 *
 * Created on December 9, 2007, 3:48 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

using System;
using System.Collections.Generic;

using HexTD.hex;
using HexTD.util;
using HexTD.ExtendNet;

namespace HexTD.tower
{
	/*
	 * The Java enum is much more powerfull than it's C# counterpart. To emulate the
	 * behavior we use extension methods. For more info, see:
	 * http://bruceboughton.me.uk/2008/06/08/emulating-java-5-enums-in-dotnet-part-2/
	 */
	public static class typeExtensions
	{
		public static int price(this TowerFactory.type t)
		{
			switch (t)
			{
				case TowerFactory.type.firecontrol: return TowerFireControl.price;
				case TowerFactory.type.upgradeDamage: return TowerUpgradeDamage.price;
				case TowerFactory.type.upgradeRange: return TowerUpgradeRange.price;
				case TowerFactory.type.greenOne: return TowerGreenOne.price;
				case TowerFactory.type.greenTwo: return TowerGreenTwo.price;
				case TowerFactory.type.greenThree: return TowerGreenThree.price;
				case TowerFactory.type.redOne: return TowerRedOne.price;
				case TowerFactory.type.redTwo: return TowerRedTwo.price;
				case TowerFactory.type.redThree: return TowerRedThree.price;
				case TowerFactory.type.yellowOne: return TowerYellowOne.price;
				case TowerFactory.type.yellowTwo: return TowerYellowTwo.price;
				case TowerFactory.type.yellowThree: return TowerYellowThree.price;
				case TowerFactory.type.blueOne: return TowerBlueOne.price;
				case TowerFactory.type.blueTwo: return TowerBlueTwo.price;
				case TowerFactory.type.blueThree: return TowerBlueThree.price;
				default:
					System.Diagnostics.Debug.WriteLine("Invalid TowerFactory.type / price unknown.");
					return 0;
			}
		}

		public static string code(this TowerFactory.type t)
		{
			switch (t)
			{
				case TowerFactory.type.firecontrol: return "fc";
				case TowerFactory.type.upgradeDamage: return "ud";
				case TowerFactory.type.upgradeRange: return "ur";
				case TowerFactory.type.greenOne: return "g1";
				case TowerFactory.type.greenTwo: return "g2";
				case TowerFactory.type.greenThree: return "g3";
				case TowerFactory.type.redOne: return "r1";
				case TowerFactory.type.redTwo: return "r2";
				case TowerFactory.type.redThree: return "r3";
				case TowerFactory.type.yellowOne: return "y1";
				case TowerFactory.type.yellowTwo: return "y2";
				case TowerFactory.type.yellowThree: return "y3";
				case TowerFactory.type.blueOne: return "b1";
				case TowerFactory.type.blueTwo: return "b2";
				case TowerFactory.type.blueThree: return "b3";
				default:
					System.Diagnostics.Debug.WriteLine("Invalid type / code unknown.");
					return "";
			}
		}
	}

	public class TowerFactory
	{
		public enum type
		{
			firecontrol,
			upgradeDamage,
			upgradeRange,
			greenOne,
			greenTwo,
			greenThree,
			redOne,
			redTwo,
			redThree,
			yellowOne,
			yellowTwo,
			yellowThree,
			blueOne,
			blueTwo,
			blueThree
		};

		public static Dictionary<string, type> table = new Dictionary<string, type>();

		static TowerFactory()
		{
			foreach (type t in Enumerator.GetValues<type>())
			{
				table.Add(t.code(), t);
			}
		}

		public static Tower createTower(type t, Context c, Hex h)
		{
			switch (t)
			{
				case type.upgradeDamage:
					return new TowerUpgradeDamage(c, h);
				case type.upgradeRange:
					return new TowerUpgradeRange(c, h);
				case type.firecontrol:
					return new TowerFireControl(c, h);
				case type.greenOne:
					return new TowerGreenOne(c, h);
				case type.greenTwo:
					return new TowerGreenTwo(c, h);
				case type.greenThree:
					return new TowerGreenThree(c, h);
				case type.redOne:
					return new TowerRedOne(c, h);
				case type.redTwo:
					return new TowerRedTwo(c, h);
				case type.redThree:
					return new TowerRedThree(c, h);
				case type.yellowOne:
					return new TowerYellowOne(c, h);
				case type.yellowTwo:
					return new TowerYellowTwo(c, h);
				case type.yellowThree:
					return new TowerYellowThree(c, h);
				case type.blueOne:
					return new TowerBlueOne(c, h);
				case type.blueTwo:
					return new TowerBlueTwo(c, h);
				case type.blueThree:
					return new TowerBlueThree(c, h);
			}
			return null;
		}
	}
}